#ifndef IO_FILTER_CHAIN_H
#define IO_FILTER_CHAIN_H
#include "io_filter.h"
#include <boost/shared_ptr.hpp>
#include <vector>
namespace vpm
{
	namespace mina
	{

		class IoFilterChain  : public IoFilter
		{
		public:
			typedef std::vector<boost::shared_ptr<IoFilter> > FilterChainType;

			virtual ~IoFilterChain()
			{
			}

			void add_filter(const boost::shared_ptr<IoFilter> & filter)
			{
				filter->filter_type(filter->filter_type());
				m_chain.push_back(filter);
			}

			virtual FilterAction process(MessageContext & msg)
			{
				IoFilter::FilterAction action;
				for (unsigned int position = 0; position < m_chain.size(); ++position)
				{	
					action = m_chain[position]->process(msg);

					if (action == IoFilter::SKIPALLCHAINS)
					{			
						return IoFilter::SKIPALLCHAINS;
					}

					if (action == IoFilter::WAITFOREVENT)
					{				
						return IoFilter::WAITFOREVENT;
					}

					if (action == IoFilter::SKIPTHISCHAIN)
					{
						return CONTINUE;
					}
				}

				return IoFilter::CONTINUE;
			}

		private:
			FilterChainType m_chain; 
		};
	}
}


#endif // IO_FILTER_CHAIN_H
